package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.Course1Dao;
import com.qfedu.stussm.dao.Course3Dao;
import com.qfedu.stussm.entity.Course1;
import com.qfedu.stussm.entity.Course3;
import com.qfedu.stussm.service.intf.Course1Service;
import com.qfedu.stussm.service.intf.Course3Service;
import com.qfedu.stussm.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Course3ServiceImpl implements Course3Service {
    @Autowired
    private Course3Dao dao;
    @Override
    public int add(Course3 course3) {
        return dao.add(course3);
    }

    @Override
    public PageBeanVo selectAll(int page, int limit,String c3_name) {
        PageHelper.startPage(page, limit);
        if (c3_name != null && c3_name.length() >0){
            c3_name = "%"+c3_name+"%";
        } else {
            c3_name = null;
        }

        PageInfo<Course3> coursePageInfo = new PageInfo<>(dao.selectAll(c3_name));
        return new PageBeanVo(coursePageInfo.getTotal(), coursePageInfo.getList());
    }

    @Override
    public int update(Course3 course3) {
        return dao.update(course3);
    }

    @Override
    public int del(int c3_id) {
        return dao.del(c3_id);
    }
}
